//
//  Ext+NSAttributedString.swift
//  web
//
//  Created by 张卓 on 2017/2/11.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

extension NSAttributedString{
    class func emoticonAttributedString(emoticonModel : ZZEmoticonModel)->NSAttributedString{
        //创建一个文本附件
//        let att = NSTextAttachment()
        let att = ZZTextAttachment()
        //赋值
        att.emoticonModel = emoticonModel
        let path = emoticonModel.path ?? ""
        //获取bundle文件中的图片
        let image = UIImage(named: path, in: ZZEmoticonTools.shared.emoticonBundle, compatibleWith: nil)
        //设置image
        att.image = image
        //得到行号
        let font = UIFont.systemFont(ofSize: ZZNORMALFONTSIZE)
        let linHeight = font.lineHeight
        // bounds 给 image设置大小
        att.bounds = CGRect(x: 0, y: -4, width: linHeight, height: linHeight)
        //创建一个不可变富文本
        let attr = NSAttributedString(attachment: att)
        return attr
    }
}
